<label> is a sequence of at least two alphanumerics (0-9a-zA-Z_) (casesensitive).
<operand-list> is a sequence of operators seperated by commas
other than the tabs and crs, no white space is allowed.
<instruction> (and appropriate operands are:
MOVE <value>,<register> (set <register> to <value>)
ADD <value1>,<value2>,<register> (set <register> to <value1>+<value2>)
SUB <value1>,<value2>,<register> (set <register> to <value1>-<value2>)
JMP <label> (jump to line labeled with <label>)
JEQ <value1>,<value2>,<label> (jump to <label> if <value1> = <value2>)
JLE <value1>,<value2>,<label> (jump to <label> if <value1> <= <value2>)
JSR <label> (jump to subroutine at <label>)
RTS (return from subroutine)
PUSH <value> (push value on to stack)
POP <register> (pop value from stack)
[others?]
<register> is a single letter
<number> is an optioanl minus sign followed by decimal digits
<value> is a <register> or a <number>
Note that the data stack and subroutine stack are independent stacks. A RTS is used to stop the program (that is, consider that you have JSRed to the initial line of the source handle). For example:
PUSH 10
JSR setA
JSE setB
RTS
setA:
POP A
RTS
setB: MOVE A,B
RTS
Interpret takes the source handle and JSRs to it, presetting the registers according to the register array. When the code returns, the register array is set to the final value of all the registers. Both subroutine and data stacks should be large (at least 1000 entries each).
*)
unit Solution;
interface
// Do not modify the interface
uses
Types, Files;
type RegisterArray = array[0..25] of SInt32;
procedure Interpret( source: Handle; var result: RegisterArray );
implementation
// Fill in your solution and then submit this folder